package com.haier.spark.project.dao.impl

import com.haier.spark.project.dao.ISessionRandomExtractDao
import com.haier.spark.project.domain.SessionRandomExtract
import com.haier.spark.project.jdbc.JDBCHelper

import scala.collection.mutable.ListBuffer

class SessionRandomExtractDaoImpl extends ISessionRandomExtractDao{
  def insert(sessionRandomExtract: SessionRandomExtract): Int = {
    val sql:String = "insert into session_random_extract values(?,?,?,?,?)"
    val params: Array[Any] = Array(sessionRandomExtract.taskId,
      sessionRandomExtract.sessionId,
      sessionRandomExtract.startTime,
      sessionRandomExtract.searchKeywords,
      sessionRandomExtract.clickCategoryIds)
    JDBCHelper.executeUpdate(sql, params)
  }

  override def insertBatch(sessionRandomExtracts: ListBuffer[SessionRandomExtract]): Unit = {
    val sql:String = "insert into session_random_extract values(?,?,?,?,?)"
    val params: ListBuffer[Array[Any]] = new ListBuffer()
    sessionRandomExtracts.foreach(item => {
      params.append(Array(item.taskId,
        item.sessionId,
        item.startTime,
        item.searchKeywords,
        item.clickCategoryIds))
    })
    JDBCHelper.executeBatch(sql, params.toList)
  }
}
